<?php

namespace Modules\Shop\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Shop\Entities\Comment;

class CommentController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
        $data = Comment::paginate(10);
        return view('shop::comment.index',compact('data'));
    }


    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
        //dd($request->all());
        //方式一
        //$post = $request->all();
        //$post['user_id'] = auth()->user()->id;
        //Comment::create($post);

        //方式二  模型关联
        auth()->user()->comment()->create($request->all());
        //设置闪存信息并返回
        session()->flash('success','评论成功，内容审核通过后将会展示！！！');
        return back();
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function shenhe(Request $request,Comment $comment)
    {
        //将对应评论内容的状态改成1
        $comment->status = 1;
        $comment->save();
        session()->flash('success','评论内容审核通过');
        return back();

    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy(Comment $comment)
    {
        //将对应评论内容删除
        $comment->delete();
        session()->flash('success','评论内容删除通过');
        return back();

    }
}
